package com.health.adapter;

import java.util.List;

import com.health.R;
import com.health.tablebean.BD_DD_AREA;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 省市区县镇adapter
 */
public class SSQAdapter extends BaseAdapter {
	private List<BD_DD_AREA> list;
	private Context mContext;
	// 0 个人档案
	// 1 健康体检
	// 2 返回

	public SSQAdapter(Context mContext, List<BD_DD_AREA> list) {
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.ssq_listitem, null);
			vh = new ViewHolder();
			findView(vh, convertView);
			convertView.setTag(R.id.TAG_VIEWHOLDER, vh);
		} else
			vh = (ViewHolder) convertView.getTag(R.id.TAG_VIEWHOLDER);

		setData(vh, convertView, position);

		return convertView;
	}

	/**
	 * 赋值
	 * 
	 * @param h
	 * @param v
	 * @param position
	 * @author 王婷婷
	 * @date 2015年12月3日 上午10:24:28
	 */
	private void setData(ViewHolder h, View v, int position) {
		if (!TextUtils.isEmpty(list.get(position).getNAME())) {
			h.nameText.setText(list.get(position).getNAME());
		} else {
			h.nameText.setText("");
		}
	}

	private void findView(ViewHolder h, View v) {
		h.nameText = (TextView) v.findViewById(R.id.tv_ssq);

	}

	private static class ViewHolder {
		TextView nameText;
	}

}
